﻿using OneSoft.DataAccess;
using OneSoft.EntityCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BySoft.Server.DataAccess.UserCode
{
    public partial class BsOrderDataAccess
    {
        public static DataTable SelectList(string OrderID, string ProductID, string ProductName, string cpFrom, string cpEnd, int pageIndex, int PageSize, out int m_count)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    #region SQL Server
                    DataAccessParameterCollection dpc = new DataAccessParameterCollection();
                    string strcmd = @"select * from V_Order o where 1=1 ";
                    if (!string.IsNullOrEmpty(OrderID))
                    {
                        strcmd += " and o.OrderID like @OrderID";
                        dpc.AddWithValue("@OrderID", "%" + OrderID + "%");
                    }
                    if (!string.IsNullOrEmpty(ProductID))
                    {
                        strcmd += " and o.ProductID like @ProductID";
                        dpc.AddWithValue("@ProductID", "%" + ProductID + "%");
                    }
                    if (!string.IsNullOrEmpty(ProductName))
                    {
                        strcmd += " and o.ProductName like @ProductName";
                        dpc.AddWithValue("@ProductName", "%" + ProductName + "%");
                    }
                    if (!string.IsNullOrEmpty(cpFrom))
                    {
                        strcmd += " and o.BillDate >= @From";
                        dpc.AddWithValue("@From", cpFrom + " 00:00:00");
                    }
                    if (!string.IsNullOrEmpty(cpEnd))
                    {
                        strcmd += " and o.BillDate <= @End";
                        dpc.AddWithValue("@End", cpFrom + " 23:59:59");
                    }
                    strcmd += " order by o.BillDate desc";
                    return DataAccessCommon.ExecuteDataTablePaging(strcmd, pageIndex, PageSize, dpc, out m_count);
                    #endregion
                }
                catch
                {
                    throw;
                }
            }
        }

        public static DataTable GetOrderData(string id)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    #region SQL Server
                    DataAccessParameterCollection dpc = new DataAccessParameterCollection();
                    string strcmd = @"select * from V_Order where OrderID=@OrderID";
                    
                        dpc.AddWithValue("@OrderID", id);
                    return DataAccessCommon.Select(strcmd, dpc).Tables[0];
                    #endregion
                }
                catch
                {
                    throw;
                }
            }
        }
    }
}
